<?php defined('IN_IA') or exit('Access Denied');?><?php (!empty($this) && $this instanceof WeModuleSite || 1) ? (include $this->template('common/header', TEMPLATE_INCLUDEPATH)) : (include template('common/header', TEMPLATE_INCLUDEPATH));?>
<?php (!empty($this) && $this instanceof WeModuleSite || 1) ? (include $this->template('base/css', TEMPLATE_INCLUDEPATH)) : (include template('base/css', TEMPLATE_INCLUDEPATH));?>
<style>
    td{vertical-align: middle!important}
    .btn-group{margin-bottom:15px;}
</style>

<div class="btn-group" role="group" aria-label="...">
    <a href="<?php  echo aurl(2)?>" class="btn btn-default">新增</a>
    <a href="#" class="btn btn-default check-all-control">全选</a>
    <a href="<?php  echo aurl(4)?>" class="btn btn-default ajax-post confirm" data-confirm="确定要删除勾选项吗?">删除</a>
    <a href="<?php  echo aurl(18)?>" class="btn btn-warning ajax-post confirm">提醒发货</a>
</div>
<form action="javascript:void(0)" id="form_search" class="form-inline" style="float: right" method="GET" data-search-ignore="page">
    <input type="text" name="active_id" class="form-control" value="<?php  echo $_GET['active_id'];?>" placeholder="搜索编号">
    <input type="text" name="title" class="form-control" value="<?php  echo $_GET['title'];?>" placeholder="搜索标题">
<?php  if($_W['role'] != 'clerk') { ?>
    <select name="uid">
        <option value="">关联客服&emsp;</option>
        <?php  if(is_array($services)) { foreach($services as $service) { ?>
            <option value="<?php  echo $service['id'];?>" <?php  if($_GET['uid'] == $service['id']) { ?>selected="selected"<?php  } ?>><?php  echo $service['name'];?></option>
        <?php  } } ?>
    </select>
<?php  } ?>
<button class="btn btn-default">搜索</button>
</form>
<form action="javascript:void(0)" method="POST" id="form">
    <textarea name="remarks" class="form-control" placeholder="发货提醒内容请在此处编辑" style="resize:none"></textarea>
<table class="table table-striped">
    <thead>
    <tr>
        <th>#</th>
        <th>编号</th>
        <th>标题</th>
        <th>所属分类</th>
        <th>价格</th>
        <th>关联客服</th>
        <th>浏览数</th>
        <th>新/老/总</th>
        <th>到期时间</th>
        <th>状态</th>
        <th>发货提醒</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <?php  if(is_array($list)) { foreach($list as $index => $item) { ?>
    <tr>
        <td><input type="checkbox" name="id[]" class="check-all" value="<?php  echo $item['id'];?>"></td>
        <td><?php  echo $item['id'];?></td>
        <td><?php  echo $item['title'];?></td>
        <td><?php  echo $item['active_cate_title'];?></td>
        <td>￥<?php  echo $item['price'];?></td>
        <td data-planner="<?php  echo $item['service_user_id'];?>"><?php  echo $item['service_user_name'];?></td>
        <td><?php  echo $item['views'];?></td>
        <td><?php  echo $item['new'];?> / <?php  echo $item['old'];?> / <?php  echo $item['all'];?></td>
        <td><?php  echo date('Y-m-d H:i:s', $item['end_time'])?></td>
        <td><?php  echo statusName($item['status'])?></td>
        <td>
            <?php  if($item['send_status'] == 1) { ?>
                已提醒
            <?php  } else if($item['send_status'] != 3 && $item['end_time'] < TIMESTAMP) { ?>
                待发货
                <!-- 所有礼品：<?php  echo $item['new_send_count'];?> / <?php  echo $item['all'];?> <br/>
                老学员礼品：<?php  echo $item['old_send_count'];?> / <?php  echo $item['old'];?> -->
            <?php  } ?>
        </td>
        <td>
            <label><a href="<?php  echo aurl(['et'=>6, 'pid'=>$item['id']])?>">订单</a></label>
            <label><a class="modal-control" href="javascript:;" data-title="<?php  echo $item['title'];?>" data-img="<?php  echo aurl(['et'=>10,'pid'=>$item['id']])?>" data-link="<?php  echo web2app_url('main', ['pid'=>$item['id']], '', $share_url)?>" style="cursor:pointer">预览</a></label>
            <label class="dropdown">
                <a id="dLabel" data-target="#" href="javascript:;" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">更多<span class="caret"></span></a>
                <ul class="dropdown-menu" aria-labelledby="dLabel">
                    <li><a href="<?php  echo aurl(['et'=>2, 'pid'=>$item['id']])?>">修改</a></li>
                    <li><a href="<?php  echo aurl(2, ['copyid'=>$item['id']])?>">复制活动</a></li>
                    <li><a href="<?php  echo aurl(16, ['pid'=>$item['id']])?>">校长返利</a></li>
                    <li><a href="javascript:;" class="sendlog-control" data-title="<?php  echo $item['title'];?>" data-id="<?php  echo $item['id'];?>">发货状况</a></li>
                </ul>
            </label>
        </td>
    </tr>
    <?php  } } ?>
    </tbody>
</table>
<?php  echo $page;?>
</form>
<div class="modal fade bs-example-modal-sm" id="modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel"><?php  echo $item['title'];?></h4>
            </div>
            <div class="modal-body">
                <p align="center"><img src="<?php  echo aurl(['et'=>10,'pid'=>$item['id']])?>" id="qrcodeLabel" width="200"></p>
                <p class="help-block">* 请使用微信扫描二维码查看活动或 <a href="javascript:;" class="cliplink" data-text="<?php  echo web2app_url('main', ['pid'=>$item['id']], '', $share_url)?>" style="color:dodgerblue"><strong><u>复制活动链接</u></strong></a></p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭页面</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade bs-example-modal-sm" id="sendlog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog modal-sm" role="document" style="width:1200px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel"><?php  echo $item['title'];?></h4>
            </div>
            <div class="modal-body">
                <table class="table">
                  <thead>
                  <tr>
                    <th>所有礼品</th>
                    <th>发货量</th>
                    <th>老学员礼品</th>
                    <th>发货量</th>
                    <th>物流公司</th>
                    <th>物流单号</th>
                    <th>发货时间</th>
                  </tr>  
                  </thead>
                  <tbody id="send_tbody">
                    
                  </tbody>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭页面</button>
            </div>
        </div>
    </div>
</div>

<?php (!empty($this) && $this instanceof WeModuleSite || 1) ? (include $this->template('base/js', TEMPLATE_INCLUDEPATH)) : (include template('base/js', TEMPLATE_INCLUDEPATH));?>
<script>
    requirejs.config({
        appDir: '.',
        paths: {
            'clipboard': ['<?php echo WEB_RESOURCE;?>/library/clipboard.min']
        }
    });
    require(['jquery', 'clipboard'], function($, Clipboard) {

        $('.modal-control').on('click', function() {
            var data = $(this).data();
            $('#modal').find('.modal-title').html(data.title);
            $('#modal').find('#qrcodeLabel').prop('src', data.img);
            $('#modal').find('.cliplink').attr('data-text', data.link);
            $('#modal').modal('show');
        })

        $('#modal').on('hidden.bs.modal', function () {
            $('#modal').find('.modal-title').html('');
            $('#modal').find('#qrcodeLabel').prop('src', '');
            $('#modal').find('.cliplink').attr('data-text', '');
        });

        var clipboard = new Clipboard('.cliplink', {
            container: document.getElementById('modal'),
            text: function(e) {
                return $(e).attr('data-text');
            }
        });

        clipboard.on('success', function(e) {
            xalert('复制成功', true, true);
        });
        clipboard.on('error', function() {
            xalert('复制失败', false, true);
        });

        $('.sendlog-control').on('click', function() {
            var data = $(this).data();
            $('#sendlog').find('.modal-title').html(data.title);
            
            $.post("<?php  echo aurl(19)?>", {
                id: data.id
            })
            .then(function(res) {
                if(res.errno != 0) {
                    xalert(res.message, false, true);
                    return false;
                }
                var data = res.data;
                $('#send_tbody').empty();
                var s = '';
                for(var i in data) {
                    s += '<tr>\
                    <td>'+data[i].gift1_name+'</td>\
                    <td>'+data[i].gift1_num+'</td>\
                    <td>'+data[i].gift2_name+'</td>\
                    <td>'+data[i].gift2_num+'</td>\
                    <td>'+data[i].ex_name+'</td>\
                    <td>'+data[i].ex_sn+'</td>\
                    <td>'+data[i].send_time+'</td>\
                    </tr>';
                }
                $('#send_tbody').html(s);
                $('#sendlog').modal('show');
            });
        })
            
    });

</script>

<?php (!empty($this) && $this instanceof WeModuleSite || 1) ? (include $this->template('common/footer', TEMPLATE_INCLUDEPATH)) : (include template('common/footer', TEMPLATE_INCLUDEPATH));?>